package com.hyfrogx.modules.manage.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hyfrogx.common.utils.QueryExt;
import com.hyfrogx.modules.manage.dao.videoSmall.HyVideoSmallCommentDao;
import com.hyfrogx.modules.manage.entity.smallVideo.HyVideoSmallEntity;
import com.hyfrogx.modules.manage.entity.smallVideo.HyVideoSmallCommentEntiy;
import com.hyfrogx.modules.manage.service.HyVideoSmallCommentService;
import com.hyfrogx.modules.manage.service.HyVideoSmallService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Map;

@Service
public class HyVideoSmallCommentServiceImpl extends ServiceImpl<HyVideoSmallCommentDao, HyVideoSmallCommentEntiy> implements HyVideoSmallCommentService {

	@Autowired
	private HyVideoSmallService hyVideoSmallService;


	@Override
	public IPage getCommentsById(QueryExt queryExt,Integer id) {
		List list= this.baseMapper.getCommentbyId(queryExt,id);
		queryExt.setRecords(list);
		return queryExt;
	}

	@Override
	public void deleteCommentById(Integer id) {
		HyVideoSmallCommentEntiy wuliComment =this.baseMapper.selectById(id);
		if(wuliComment!=null){
			HyVideoSmallEntity wuli = hyVideoSmallService.getById(wuliComment.getWid());
			wuli.setComment(wuli.getComment()-1);
			//获取今天0点的时间戳
			Calendar calendar = Calendar.getInstance();
			calendar.setTime(new Date());
			calendar.set(Calendar.HOUR_OF_DAY, 0);
			calendar.set(Calendar.MINUTE, 0);
			calendar.set(Calendar.SECOND, 0);
			long zero = calendar.getTime().getTime();
			Date mdate = wuliComment.getCreateTime();
			//如果评论时间在今天发生
			if(mdate.getTime() > zero){
				wuli.setDayComment(wuli.getDayComment() -1);
			}
			this.baseMapper.deleteById(id);
			hyVideoSmallService.getBaseMapper().updateById(wuli);
		}
	}



//	@Override
//	public void getwuliforclientByid(Integer id) {
//		Wuli wuli =	wuliMapper.selectByPrimaryKey(id);
//		wuli.setAttention(wuli.getAttention()+1);
//		wuli.setDayattention(wuli.getDayattention()+1);
//		wuliMapper.updateByPrimaryKeySelective(wuli);
//	}
//
//





//
//

//
//
//	@Override
//	public List<MuliSource> getapkbyid(Integer id) {
//
//		return muliSourceMapper.getapkbyid(id);
//	}
//

//
//	@Override
//	public Wuli sharewulibyId(Integer id) {
//		// TODO Auto-generated method stub
//		return wuliMapper.selectByPrimaryKey(id);
//	}
//
//
//	@Override
//	public WuliLike getWuliLike(Integer uid, Integer wid) {
//		// TODO Auto-generated method stub
//		return wuliLikeMapper.judelike(wid, uid);
//	}
//
//
//
//
//	@Override
//	public Wuli updatewuliforclientByid(Integer id, Integer uid) {
//		Wuli result = wuliMapper.selectByPrimaryKey(id);
//		WuliLike like =	wuliLikeMapper.judelike(id,uid);
//		if(like!=null){
//			result.setIslike(1);
//		}else{
//			result.setIslike(0);
//		}
//		return result;
//	}



}
